<?php

include(__DIR__.'/Notifier/Abstract.php');

class McCube_Notifier {

    protected static $_context = array();
    protected static $_enginesInstances = array();
    protected static $_engines = array(
        'web'         => array(
              'browser:text' => 'McCube_Notifier_Browser_Text'
            , 'browser:json' => 'McCube_Notifier_Browser_Json'
            , 'browser:html' => 'McCube_Notifier_Browser_Html'
            , 'syslog'       => 'McCube_Notifier_Syslog'
        )
        , 'shell'     => array(
              'console'      => 'McCube_Notifier_Console'
            , 'syslog'       => 'McCube_Notifier_Syslog'
        )
    );

    public static function isRenderOn(){
        return count(self::$_enginesInstances);
    }

    public static function init($config){
        self::initEngine($config['engines'][self::$_context]);
    }

    public static function setContext($context){
        self::$_context = $context;;
    }

    public static function initEngine($engine){
        foreach((array)$engine as $type){
            if(!isset(self::$_engines[self::$_context][$type]))
                continue;

            if(!isset(self::$_enginesInstances[$type]))
                self::$_enginesInstances[$type] = new self::$_engines[self::$_context][$type]();
        }
    }

    public static function render($title, $msg, $backtraces=true){
        foreach(self::$_enginesInstances as $engine){
            echo $engine->render($title, $msg, $backtraces);
        }
    }

}